<template>
	<view class="" style="background-color: #f8f8f8;">
		<view class="" style="height: 26rpx;"></view>
		<view class="" style="background-color: #fff;padding: 0 30rpx;">
			<u-form :model="form" ref="uForm">
					<u-form-item label="收件人" label-width="150">
						<u-input v-model="form.a" type="select" @click="show = true" />
						<u-select v-model="show" :list="list" @confirm="confirm"></u-select>
					</u-form-item>
					<u-form-item label="标题" label-width="150">
						<u-input v-model="form.name" />
					</u-form-item>
					<u-form-item label="内容" label-width="150">
						<u-input v-model="form.content" :type="type" :border="border" :height="height" :auto-height="autoHeight" />
					</u-form-item>
					<u-form-item label="附件" label-width="150">
						<u-upload ref="uUpload" :action="action" :file-list="fileList" :header="UPheader" upload-text="上传附件" max-count="1"></u-upload>
						<!-- <u-upload :action="action" :file-list="fileList" ></u-upload> -->
						<!-- <u-input v-model="form.content" :type="type" :border="border" :height="height" :auto-height="autoHeight" /> -->
					</u-form-item>
				</u-form>
		</view>
		<view class="" style="padding: 0 30rpx;position: absolute;bottom: 100rpx;width: 100%;">
			<u-button type="primary" shape="circle" @click="submit">发送</u-button>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			form: {
				a:'董事长',
				name: '',
				content: '',
				file:''
			},
			UPheader:{
				token:''
			},
			// 演示地址，请勿直接使用
			action: 'http://8.133.192.220:8003/api/common/upload',
			// action: 'http://175.27.169.240:8101/common/upload',
			fileList: [],
			show: false,
			show2: false,
			list: [
				{
					value: '1',
					label: '董事长'
				}
			],
			value: '',
			type: 'textarea',
			border: true,
			height: 100,
			autoHeight: true,
			radio: '',
			switchVal: false
		};
	},
	onLoad() {
		this.UPheader.token = uni.getStorageSync('token')
	},
	methods:{
		confirm(e) {
			console.log(e);
			this.form.levelN = e[0].label
			this.form.level = e[0].value
		},
		confirm2(e) {
			console.log(e);
			this.form.remindDate = e.year + '-' + e.month + '-' + e.day + ' ' + e.hour + ':' + e.minute + ':' + e.second
			// this.form.levelN = e[0].label
			// this.form.level = e[0].value
		},
		async submit(){
			// console.log(this.fileList)
			let files = [];
			// 通过filter，筛选出上传进度为100的文件(因为某些上传失败的文件，进度值不为100，这个是可选的操作)
			files = this.$refs.uUpload.lists.filter(val => {
				return val.progress == 100;
			})
			// 如果您不需要进行太多的处理，直接如下即可
			// files = this.$refs.uUpload.lists;
			console.log(files)
			if(files.length>0){
				this.form.file = files[0].response.data.fullurl
			}
			console.log(this.form)
			const res = await this.$api.Mailbox({'name':this.form.name,'content':this.form.content,'files':this.form.file})
			console.log(res)
			if(res.code==1){
				uni.navigateBack()
			}else{
				this.$refs.uToast.show({
					title: res.msg,
					type: 'error'
				})
			}
		}
	}
};
</script>

<style>
</style>